<?php
/**
 * Tips-Database's  Operators
 *Table:tab_area,tips_day,tips_hour
 * @author Zhoubc
 *
 */
class Model_Tips extends Bcms_Db_Table
{
	 protected $_name = 'tab_area';
	 
	 protected $_per_pages = 10 ; //每页显示的条数
	 
	

	public function getTipsOnArea($table_name,$currentPage)
	 {
	 	
	 	$this->_name = $table_name;
	 	$this->counts($table_name);
	 	
	 	$offset = intval($this->_per_pages*$currentPage);
	 	$select = $this->_db->select(); 	
	 	$select->from($table_name,'*'); 
		$select->limit($this->_per_pages, $offset);			

		
	 	$select->order('id desc'); 
		
	 	/*Query with condition*/
//	 	$select->where('trim(sales_name)<>?', '');
	 	
//		echo $select->__toString();					
		$tips = $this->_db->fetchAll($select->__toString());
		return $tips;
		
	 }
	 
    
	 /**
	  * Get all the rows
	  */
	 public function counts($table_name)
	 {
	 	$select = $this->_db->select() 	
	 						->from($this->_name,'count(*) as num');
	 	$r_counts = $this->_db->fetchRow($select->__toString());
	 	if(!$r_counts)  return 0;
	 	
	 	return intval($r_counts->num);
	 }
	 
 	/**
	 * @return the $_per_pages
	 */
	public function get_per_pages() {
		return $this->_per_pages;
	}

	/**
	 * @param $_per_pages the $_per_pages to set
	 */
	public function set_per_pages($_per_pages) {
		$this->_per_pages = $_per_pages;
	}
	 
	 
	
}